package com.usian.day11.springsession.controller;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author baimugudu
 * @email 2415621370@qq.com
 * @date 2023/8/8 14:32
 */
@RestController
@Slf4j
public class SessionController {

    @GetMapping("/getVlaue")
    public String getVlaue(String key, HttpSession session){
        String  sessionAttribute = (String)session.getAttribute(key);
        log.info("sessionAttribute:{}",sessionAttribute);
        return "OK";
    }

    @GetMapping("/setValue")
    public String setValue(String key, String value, HttpSession session){
        session.setAttribute(key,value);
       return "OK";
    }

    public static void main(String[] args){
        Snowflake snowflake = IdUtil.getSnowflake();
        long l = snowflake.nextId();
        log.info("l:{}",l);

    }
}
